package com.crrc.sandameter.vm

import com.cj.mvvmlib.base.viewmodel.BaseViewModel
import com.cj.mvvmlib.ext.util.GsonInstance
import com.crrc.sandameter.http.API
import com.crrc.sandameter.http.POST
import com.crrc.sandameter.http.http
import org.json.JSONObject

class DataCollectionViewModel : BaseViewModel() {
    /**
     * 提交数据
     */
    fun submitData(taskId: String, sgItemId: String, submitPerson: String, dataList: String) {
        http {
            url = API.getBaseUrl() + API.TASK_SUBMIT
            requestType = POST
            parameterBuilder.add("taskId", taskId).add("sgItemId", sgItemId)
                .add("submitPerson", submitPerson).add("dataList", dataList)
            success = {}
            fail = { code, message -> }
        }
    }

    fun submitData(data: String) {
        http {
            url = API.getBaseUrl() + API.TASK_SUBMIT
            val json = GsonInstance.getInstance().gson.toJson("")
            val postJson = JSONObject(json)
            body = postJson
            success = {}
            fail = { code, message -> }
        }
    }
}